package com.ljb.android.component

import android.content.Context
import com.blankj.utilcode.util.SPStaticUtils
import com.ljb.android.comm.BuildConfig
import com.ljb.android.comm.common.CommConstant
import com.ljb.android.component.comm.AppConstant
import net.ljb.kt.HttpConfig

object AppInit {

    //TODO 此处初始化App组件所需要的功能
    fun init(context: Context) {
        initHttp()
    }

    private fun initHttp() {
        HttpConfig.Builder(BuildConfig.HTTP_HOST)
            .addCommCookie(object : HttpConfig.ICommCookie {
                //Cookie 持久化
                override fun saveCookie(host: String, cookie: String) {
                    SPStaticUtils.put(host, cookie)
                }

                override fun loadCookie(host: String): String? {
                    return SPStaticUtils.getString(host)
                }
            }).addCommHeader { headers ->
                headers["from"] = "app"
            }.addCommParam { params ->
            }.openLog(BuildConfig.DEBUG)
            .newClientByTag(AppConstant.MODULE_NAME)
            .build()
    }
}